package com.geekbang.supermarket;

public class LittleSuperMarket {
    public String superMarketName;
    public String address;
    public int parkingCount;
    public double incommingSum;
    public Merchandise[] merchandises;
    public int[] merchandiseSold;

    public Merchandise getBiggestProfitMerchandise() {
        Merchandise curr = null;
        for (int i = 0; i < merchandises.length; i ++) {
            Merchandise m = merchandises[i];
            if (curr == null) {
                curr = m;
                continue;
            }

            // >> 调用商品中定义的方法，不同的实例调用相同的方法，虽然代码相同，但是每个实例内部的数据不同，所以返回值不同
            double currProfit = curr.calculateProfit();
            double newProfit = m.calculateProfit();
            if (newProfit > currProfit) {
                curr = m;
            }
        }
        return curr;
    }
}
